// Bean2.java：实现方式——通过Spring接口
package com.beantest;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

public class Bean2 implements InitializingBean, DisposableBean {
    private String type;

    // 实例化
    public Bean2() {
        System.out.println("bean2 实例化");
    }

    // 属性赋值
    public void setType(String type) {
        System.out.println("bean2 属性赋值");
        this.type = type;
    }

    // 初始化方法1：实现InitializingBean接口
    @Override
    public void afterPropertiesSet() {
        System.out.println("bean2 初始化（InitializingBean接口）");
    }

    // 销毁方法1：实现DisposableBean接口
    @Override
    public void destroy() {
        System.out.println("bean2 销毁（DisposableBean接口）");
    }

    @Override
    public String toString() {
        return "Bean2当前状态: type=" + type;
    }
}
